<div class="row">
	<div class="col-md-12">
		<form id="form">
            <input type="hidden" class="form-control" name="orgId" id="orgId" value="${orgId}">
			<div class="modal-body">
				<div class="form-group" >
					<label id="nameLabel">用户名</label>
					<input type="text" class="form-control" name="username" id="username" placeholder="输入登录用户名">
				</div>
				<div class="form-group">
					<label id="passwordLabel">密码</label>
					<input type="text" class="form-control" name="password" id="password" placeholder="输入登录密码">
				</div>
				<div class="form-group">
					<label>部门</label>
                   <input type="text" class="form-control" readonly value="${orgName!}">
				</div>
                <div class="form-group">
                    <label id="roleLabel">角色</label>
                    <select name="roleId" id="roleId" class="form-control select2" style="width: 100%;">
                        <option value="">选择角色</option>
                        <#list list as item>
                        <option value="${item.id}">${item.role}(${item.description})</option>
                        </#list>
                    </select>
                </div>
                <div class="form-group">
                    <label>状态</label>
                    <select name="status" class="form-control select2" style="width: 100%;">
                        <option value="1">启用</option>
                        <option value="0">停用</option>
                    </select>
                </div>
			</div>
			<div class="modal-footer">
				<div class="pull-right">
					<button type="button" class="btn btn-default btn-sm" data-dismiss="modal"><i class="fa fa-close"></i>关闭</button>
					<button type="button" class="btn btn-primary btn-sm" onclick="userformSave()"><i class="fa fa-save"></i>保存</button>
				</div>
			</div>
		</form>
	</div>
</div>

<script type="text/javascript">


    var userformSave = function (){
        $("span").remove(".errorClass");
        $("br").remove(".errorClass");
        var status = 1;
        if($("#username").val()==""){
            $("#nameLabel").prepend('<span class="errorClass" style="color:red">*用户名不能为空</span><br class="errorClass"/>');
            status = 0;
        }
        if($("#password").val()==""){
            $("#passwordLabel").prepend('<span class="errorClass" style="color:red">*密码不能为空</span><br class="errorClass"/>');
            status = 0;
        }
        if($("#roleId").val()==""){
            $("#roleLabel").prepend('<span class="errorClass" style="color:red">*请选择角色</span><br class="errorClass"/>');
            status = 0;
        }

        if(status == 0){
            return false;
        }else{
            $.ajax({
                url: '/admin/user/save',
                type: 'post',
                dataType: 'json',
                data: $("#form").serialize(),
                success: function (data) {
                    if (data.code == 0){
                        $("#lgModal").modal('hide');
                        alertMsg("添加成功","success");
                        tbReload();
                    }else {
                        $("#nameLabel").prepend('<span class="errorClass" style="color:red">用户名已经存在</span><br class="errorClass"/>');
                    }
                }
            });
        }
    }


</script>